package com.venueproject.controlle;


import com.venueproject.pojo.PageBean;
import com.venueproject.pojo.Venue;
import com.venueproject.service.VenueService;
import lombok.extern.slf4j.Slf4j;
import com.venueproject.pojo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


//请求处理类
@RestController
@CrossOrigin(origins="*")
@Slf4j
@RequestMapping("/venue")
public class VenueControll {


    @Autowired
    private VenueService venueService;


    @GetMapping("/login")
    public Result entry(@RequestParam("username") String username, @RequestParam("password") String password) {
        log.info("登录");
        return Result.success(venueService.entry(username,password));
    }

    @GetMapping("/change")
    public Result Changstatus(@RequestParam("id") int id) {
        log.info("维护或开放场地，编号:{}", id);
        venueService.Changestatus(id);
        return Result.success();
    }


    @GetMapping()
    public Result page(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "6") Integer pageSize,
                         String number, String name){
        log.info("分页查询, 参数: {},{}",page,pageSize);
        //调用service分页查询
        PageBean pageBean = venueService.page(page,pageSize,number,name);
        return Result.success(pageBean);
    }

    @PostMapping("/change")
    public Result update(@RequestBody Venue venue) {
        log.info("修改场地{}", venue);
        venueService.update(venue);
        return Result.success();
    }

    @DeleteMapping("/delete")
    public Result DeleteByid(@RequestParam("id") int id) {
        log.info("修改场地id为{}", id);
        venueService.DeleteByid(id);
        return Result.success();
    }

    @PostMapping("/add")
    public Result Addvenue(@RequestBody Venue venue) {
        log.info("增加场地{}", venue);
        venueService.Addvenue(venue);
        return Result.success();
    }






}
